package com.ssr.master.common.Base;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.ssr.master.common.utils.Reflections;
import com.ssr.master.common.utils.StringUtils;
import javax.validation.constraints.NotNull;

/**
 * @author ZhangPeng
 * @Description //todo
 * @date
 * @updateBy
 * @other
 **/

public abstract class TreeEntity<T> extends BaseEntity<T> {
    private static final long serialVersionUID = 1L;
    protected T parent;
    protected String parentIds;
    protected String name;


    public TreeEntity(String id) {
        super(id);
    }

    @JsonBackReference
    @NotNull
    public abstract T getParent();

    public abstract void setParent(T var1);

//    @Length(
//            min = 1,
//            max = 2000
//    )
    public String getParentIds() {
        return this.parentIds;
    }

    public void setParentIds(String parentIds) {
        this.parentIds = parentIds;
    }

//    @Length(
//            min = 1,
//            max = 100
//    )
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public String getParentId() {
        String id = null;
        if (this.parent != null) {
            id = (String) Reflections.getFieldValue(this.parent, "id");
        }

        return StringUtils.isNotBlank(id) ? id : "0";
    }


}
